<template>
  <!-- 放置一个图标 -->
  <div>
    <svg-icon
      :icon-class="isFullscreen ? 'exit-fullscreen' : 'fullscreen'"
      class="fullscreen"
      @click="toggle"
    />
    {{ isFullscreen }}
  </div>
</template>

<script>
import screenfull from 'screenfull'
console.log(screenfull)
export default {
  name: 'ScreenFull',
  data() {
    return { isFullscreen: false }
  },
  // 监听当前全屏状态
  created() {
    // ESC会改变当前的全屏状态
    // screenfull是插件，它自带事件监听 on
    // screenfull.isFullscreen ：插件自带的属性，表示当前是否处于全屏状态
    screenfull.on('change', () => {
      console.log('screenfull的状态变化了', screenfull)
      this.isFullscreen = screenfull.isFullscreen
    })
  },
  methods: {
    toggle() {
      screenfull.toggle()
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
